﻿// *********************************************************************
// [DCOM Productions]
// [Copyright (C) DCOM Productions All rights reserved.]
// *********************************************************************

namespace BitFlex.Windows.Forms {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    /// <summary>
    /// The Windows Explorer ListView
    /// </summary>
    [ToolboxBitmap(typeof(ListView))]
    public sealed partial class ExplorerListView : System.Windows.Forms.ListView {
        /// <summary>
        /// Instantiates a new instance of the BitFlex.Windows.Forms.ListViewEx class
        /// </summary>
        public ExplorerListView() {
            InitializeComponent();

            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            UpdateStyles();
        }

        #region Platform Invoke

        [DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
        private static extern Int32 SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList);

        #endregion

        #region Properties

        private Boolean m_IsExplorerStyle;
        /// <summary>
        /// Gets a value indicating whether the Windows Explorer styles are applied to the control
        /// </summary>
        public Boolean IsExplorerStyle {
            get {
                return m_IsExplorerStyle;
            }
        }

        #endregion

        /// <summary>
        /// Overrides the base OnHandleCreated method
        /// </summary>
        protected override void OnHandleCreated(EventArgs e) {
            base.OnHandleCreated(e);

            if (!m_IsExplorerStyle) {
                Tag = SetWindowTheme(Handle, "explorer", null);
                m_IsExplorerStyle = true;
            }
        }
    }
}